package test2;

public class demo105 {
    /*
    *
    * 合并区间
    * [[1,3][3,6][7,9][5,8]]         [[1,9]]        注：只要右区间的值大于等于下一个数组的左区间就可以进行区间合并
    * */
/*    class Solution {
        public int[][] merge(int[][] inter) {
            if(inter.length == 0) return new int[0][2];
            if(inter.length == 1) return inter;
            //先排序
            int len = inter.length;
            Arrays.sort(inter,new Comparator<int[]>(){
                public int compare(int[] inter1,int[] inter2)
                {
                    return inter1[0]-inter2[0];
                }
            });
            //再合并
            List<int[]>ans = new ArrayList<>();
            for(int i = 0;i<len;i++)
            {
                int l = inter[i][0],r = inter[i][1];
                if(ans.size()==0||ans.get(ans.size()-1)[1]<l)
                {
                    ans.add(new int[]{l,r});
                }
                //更新右端点
                else{
                    ans.get(ans.size()-1)[1] = Math.max(r,ans.get(ans.size()-1)[1]);
                }
            }
            return ans.toArray(new int[ans.size()][]);
        }
    }*/
}
